package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.*;
import com.cskaoyan.market.db.mapper.MarketGoodsMapper;
import com.cskaoyan.market.db.mapper.MarketGoodsProductMapper;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import com.cskaoyan.market.db.mapper.MarketUserMapper;
import com.cskaoyan.market.service.DashboardService;
import com.cskaoyan.market.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DashboardServiceImpl implements DashboardService {


    @Override
    public MarketBasicInfo dashboard(HttpServletRequest req, HttpServletResponse resp) {

        MarketBasicInfo marketBasicInfo = new MarketBasicInfo();

        SqlSession session = MybatisUtils.getSession();

        MarketGoodsMapper marketGoodsMapper =  session.getMapper(MarketGoodsMapper.class);
        MarketGoodsExample marketGoodsExample = new MarketGoodsExample();

        MarketGoodsProductMapper marketGoodsProductMapper = session.getMapper(MarketGoodsProductMapper.class);
        MarketGoodsProductExample marketGoodsProductExample = new MarketGoodsProductExample();

        MarketUserMapper marketUserMapper = session.getMapper(MarketUserMapper.class);
        MarketUserExample marketUserExample = new MarketUserExample();

        MarketOrderMapper marketOrderMapper = session.getMapper(MarketOrderMapper.class);
        MarketOrderExample marketOrderExample = new MarketOrderExample();

        long goodsTotal = marketGoodsMapper.countByExample(marketGoodsExample);
        long goodsProductTotal = marketGoodsProductMapper.countByExample(marketGoodsProductExample);
        long userTotal = marketUserMapper.countByExample(marketUserExample);
        long orderTotal = marketOrderMapper.countByExample(marketOrderExample);

        marketBasicInfo.setGoodsTotal(goodsTotal);
        marketBasicInfo.setProductTotal(goodsProductTotal);
        marketBasicInfo.setUserTotal(userTotal);
        marketBasicInfo.setOrderTotal(orderTotal);

        session.close();
        return marketBasicInfo;


    }
}
